<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of model_page
 *
 * @author b4by
 */
class model_page extends MY_Model {

	var $table = 'page';

	public function get_info($id, $field = '') {
		$page = parent::get_info($id, $field);
		if (!$page)
			return FALSE;
		$this->load->model('model_page_catalogue');
		$catalogues = $this->model_page_catalogue->get_list(array(
			'select' => 'cat_id',
			'where' => array('page_id' => $page->id),
			'order' => array('cat_id', 'desc')
				));

		$page->catalogues = array();
		foreach ($catalogues as $cat)
			$page->catalogues[] = $cat->cat_id;

		return $page;
	}

	public function get_list($input = array()) {
		if (!isset($input['select']))
			$input['select'] = 'p.*';

		$this->db->from('page p');

		$this->db->join('page_catalogue c', 'p.id=c.page_id', 'left');

		$this->db->group_by('p.id');

		$this->get_list_set_input($input);

		$query = $this->db->get();

		return $query->result();
	}

	public function get_total($where = array()) {
		$this->db->from('page p');
		$this->db->join('page_catalogue c', 'p.id=c.page_id', 'left');
		$this->db->group_by('p.id');
		$this->db->where($where);
		return $this->db->count_all_results();
	}

}

?>
